from datetime import datetime,timedelta
from pytz import timezone

def convert_time(time_input):
    """时间转换（强制转换为Asia/Shanghai时区）"""
    # 原始转换逻辑
    if isinstance(time_input, str):
        try:
            naive_time = datetime.strptime(time_input, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            naive_time = datetime.strptime(time_input, '%Y-%m-%d')
    elif isinstance(time_input, datetime):
        naive_time = time_input.replace(tzinfo=None)  # 剥离原有时区信息
    else:
        raise ValueError("时间参数必须是datetime对象或'YYYY-MM-DD [HH:MM:SS]'格式")

    # 本地化为Asia/Shanghai时区
    shanghai_tz = timezone('Asia/Shanghai')
    return shanghai_tz.localize(naive_time)  # 转换为带时区的时间对象


